﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using TAMS;

namespace TAMS.Admin
{


    public partial class Admin_Instructor : System.Web.UI.MasterPage
    {
        MySqlConnection conn;
        MySqlCommand sqlCommand;
        MySqlDataReader readVals;
        string strProvider = Resource1.databaseConnection;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            HttpCookie tmp = new HttpCookie("LastVisit");
            tmp.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(tmp);
            Response.Redirect("../login.aspx");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Admin_InstructorAdd.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            GridView gw = (GridView)(this.ContentPlaceHolder2.FindControl("GridView1"));
            string key = null;

            try
            {
                key = gw.SelectedValue.ToString();
            }
            catch (System.Exception ex)
            {
            	
            }

            if (key != null)
            {
                Response.Redirect("Admin_InstructorModify.aspx" + "?id=" + key);
            }
            else
                System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert(\"Select a instructr member !\");</SCRIPT>");
            
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            GridView gw = (GridView)(this.ContentPlaceHolder2.FindControl("GridView1"));
            string key = null;

            try
            {
                key = gw.SelectedValue.ToString();
            }
            catch (System.Exception ex)
            {

            }

            if (key != null)
            {
                // Connect to the Database
                conn = new MySqlConnection(strProvider);
                conn.Open();

                string deletStaff = "DELETE" +
                                    " FROM Staff" +
                                    " WHERE fsid="+key;

                sqlCommand = new MySqlCommand(deletStaff, conn);
                readVals = sqlCommand.ExecuteReader();
                Response.Redirect("Admin_Instructor.aspx");
            }
            else
                System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert(\"Select a faculty member !\");</SCRIPT>");

        }
    }
    
}